import requests
from apiKeys import get_qwen_api_key
def image_to_text(picture_url, text_prompt):
    url = "https://api.siliconflow.cn/v1/chat/completions"
    headers = {
        "Authorization": get_qwen_api_key(),
        "Content-Type": "application/json"
    }

    payload = {
        "model": "Qwen/Qwen2.5-VL-32B-Instruct",
        "messages": [
            {
                "role": "user",
                "content": [
                    {
                        "type": "image_url",
                        "image_url": {
                            "url": picture_url
                        }
                    },
                    {
                        "type": "text",
                        "text": text_prompt
                    }
                ]
            }
        ]
    }

    response = requests.post(url, headers=headers, json=payload)
    response_data = response.json()
    print(response_data)
    content = response_data["choices"][0]["message"]["content"]
    cleaned_content = content.replace("\n", "")
    return cleaned_content

if __name__ == "__main__":
    picture_url = "https://liblibai-tmp-image.liblib.cloud/img/8b3c5ba978a849588d8136b56d80c4ba/67655e55e377686f94dcb486d1bffe85b9692b822322f2d4b8f666851c328eb1.png"
    text = image_to_text(picture_url,text_prompt="请描述这张图片")
    print(text)